% Bayes Classfiers
% [masks,newimage] = bc(image,normsh,nnsh)
% cp is the cost for false positive
% cn is the cost for miss detection
function [masks,newimage] = bc(image,normsh,nnsh)
	% Skin/NonSkinRatio
	snratio = 1.6;
	theta = snratio;
    
	[x,y,~] = size(image);
    
	masks = zeros(x,y);
    for i=1:x
        for j=1:y
            pixel = image(i,j,:);
            r = pixel(1)+1;
            b = pixel(2)+1;
            g = pixel(3)+1;
            skinprob = normsh(r,g,b);
            nonskinprob = nnsh(r,g,b);

            if (nonskinprob < .0000000001 && skinprob > 0.00000001)
                ratio = 100;
            else
                ratio = skinprob/nonskinprob;
            end

            if(ratio > theta)			
                masks(i,j) = 1;
            end
        end
    end
    
    s = strel('disk',2);
    masks = imopen(masks,s);
    newimage = image;
end
